package com.cn.wanxi.servlet.product;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.service.IProductService;
import com.cn.wanxi.service.impl.ProductServiceImpl;
import com.cn.wanxi.util.MyIO;
import com.cn.wanxi.util.MyImg;
import com.cn.wanxi.util.MyPath;
import com.cn.wanxi.util.MyTool;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;

@WebServlet("/back/product/add")
public class ProductAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        MyImg.upload(req);
        ProductModel productModel = new ProductModel();
        productModel.setName((String) req.getAttribute("productName"));
        productModel.setNormalPrice(MyTool.parseDouble(req.getAttribute("normalPrice")));
        productModel.setPrice(MyTool.parseDouble(req.getAttribute("price")));
        productModel.setCuisineId(MyTool.parseInt(req.getAttribute("cuisine")));
        productModel.setImgHref((String) req.getAttribute("imgHref"));
        productModel.setIsShow(MyTool.parseInt(req.getAttribute("isShow")));
        productModel.setIsRecommend(MyTool.parseInt(req.getAttribute("isRecommend")));

        IProductService iProductService = new ProductServiceImpl();
        String result = iProductService.add(productModel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", result);
        resp.getWriter().println(jsonObject);

/**
 * 1.字体图标  下载库，引用一个css  i标签元素
 * 2.弹出框  position   show    注意：加载的是一个页面，id不能相同
 * 3.产品新增：菜系的查询  菜系赋值
 * 4.图片上传格式  FormData
 * 5.需要两个jar包
 * 6.在后台得到值 遍历   把所有数据存放在request里面
 * 7.和以前一样，封装，调用服务逻辑层 调用数据实现层  返回结果
 */
    }

}
